package com.box.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.box.entity.DbPersonInfo;
import com.box.entity.DbPersonInfoExample;
import com.box.entity.DbPersonInfoExample.Criteria;
import com.box.mapper.DbPersonInfoMapper;
import com.box.service.PersonInfoService;
import com.box.utils.LayuiResult;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;


@Service
public class PersonInfoServiceImpl implements PersonInfoService {

	@Autowired
	private DbPersonInfoMapper personMapper;
	
	public LayuiResult selPersonInfoList(Integer page, Integer limit) {
		// TODO Auto-generated method stub
	PageHelper.startPage(page,  limit);
	DbPersonInfoExample example=new DbPersonInfoExample();
	Criteria createCriteria = example.createCriteria();
	List<DbPersonInfo> list = personMapper.selectByExampleWithBLOBs(example);
	try {
		PageInfo<DbPersonInfo> pageinfo=new PageInfo<DbPersonInfo>(list);
		LayuiResult result=new LayuiResult();
		result.setCode(0);
		result.setCount(pageinfo.getTotal());
		result.setMsg("获取成功");
		result.setData(pageinfo.getList());
		return result;
	} catch (Exception e) {
		// TODO: handle exception
		LayuiResult result=new LayuiResult();
		result.setCode(0);
		result.setCount(0l);
		result.setMsg("获取失败");
		result.setData(e);
		return result;
	}
	
	
	
	
	}

	public DbPersonInfo selPersonInfoById(String id) {
		// TODO Auto-generated method stub
		DbPersonInfoExample example = new DbPersonInfoExample();
		Criteria createCriteria = example.createCriteria();
		
		createCriteria .andIdEqualTo(Integer.parseInt(id));
		
		List<DbPersonInfo> list = personMapper.selectByExampleWithBLOBs(example);
		return list.get(0);
	}

	public Integer updatePersonInfoByO(DbPersonInfo personinfo) {
		// TODO Auto-generated method stub
		return personMapper.updateByPrimaryKeySelective(personinfo);
	}

}
